﻿#教学环境KVM虚拟机自动部署可以使用的yum源
#/bin/bash

#提示信息
echo “本脚会将YUM源自动配置为192.168.2.254！”

#主循环开始
while :
do
read -p '是否继续运行此脚本y/n' p
if [ $p == y ] ; then 

#测试网络
ping -c5 -i0.01 192.168.2.254
[ $? -ne 0 ] &> /dev/null && echo "请检查网络！" && exit || echo “网络检查正常！”
sleep 0.5

#修改yum源
sed -i '3s/192.168.4.254/192.168.2.254/' /etc/yum.repos.d/local.repo
yum clean all
yum makecache 
i=`yum repolist | sed -n '$p' | sed 's/,//g' | awk '{print $2}'`
echo "软件包仓库现有:$i 个包！Finsh!"

#检查yum源是否安装
i=`yum repolist | sed -n '$p' | sed 's/,//g' | awk '{print $2}'`
[ $i -le 9000 ] &> /dev/null && echo "配置失败！请检查yum源相关配置！" && exit
echo "检查yum源正常!"
echo "Finish!"
exit

#主循环判断末尾
elif [ $p == n ] ; then
	exit
else
	echo "请输入y/n!"
fi
done